<template>
	<view>
		<view class="address-window" :class="isSign==true?'on':''">
			<view class='title'>
				<view class="iconfont left" style="left: 15px;">
					<u-icon name="checkmark" color="#888" size="20" @click='agree()'></u-icon>
				</view>
				签署协议
				<view class="iconfont">
					<u-icon name="close" color="#888" size="20" @click='close'></u-icon>
				</view>
			</view>
			<view class='box'>
				<view class="txt">用户在仔细阅读并同意所有服务条款完成注册程序后即时成为平台的正式用户。本注册协议自用户注册成功之日起，在用户与平台之间发生法律效力。</view>
				<view v-if="!signImg" class="sign" @click="sign()">签字区</view>
				<view v-else @click="sign()">
					<image class="signimg" :src="signImg"
						mode="widthFix"  />
				</view>
				
			</view>
		</view>
		<view class='mask' catchtouchmove="true" :hidden='isSign==false' @click='close'></view>
	</view>
</template>

<script>
	import {
		uploadBase64Image
	} from "@/api/my.js";
	import {
		IMG_URL,
	} from "../../config/app.js";
	export default {
		props: {
			isSign: {
				type: Boolean,
				default: true,
			},
			shipid: {
				type: Number,
				default: 0
			},
		},
		data() {
			return {
				IMG_URL: IMG_URL,
				signImg: ''
			};
		},
		created() {
			let that = this
			uni.$on('isRefresh',function(data){
				that.signImg = data
			})
		},
		methods: {
			close: function() {
				this.$emit('changeClose');
			},
			toJump(url) {
				if (!url) return
				uni.navigateTo({
					url
				});
			},
			async agree(){
				
				let data = {
					'base64_image': this.signImg,
					'ship_id':this.shipid
				}
				console.log('保存签名',data);
				let res = await uploadBase64Image(data).then(res => {
					console.log(res,'8888888888');
					if(res.code == 1){
						uni.showToast({
							'icon':'none',
							'title':res.msg,
							'duration':1500
						})
						uni.$emit('sign', res.data)
						this.$emit('changeClose');
					}
				});
			},
			sign(){
				console.log('开始签名');
				uni.navigateTo({
					url:'/pages/love/sign'
				})
			},
			
		}
	}
</script>

<style scoped lang="scss">
	.address-window {
		background-color: #f6f6f6;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		z-index: 101;
		transform: translate3d(0, 100%, 0);
		transition: all .3s cubic-bezier(.25, .5, .5, .9);
		border-radius: 30rpx 30rpx 0 0;
	}

	.address-window.on {
		transform: translate3d(0, 0, 0);
	}

	.address-window .title {
		font-size: 28rpx;
		text-align: center;
		height: 100rpx;
		color: $uni-text-color-placeholder;
		line-height: 100rpx;
		position: relative;
	}

	.address-window .title .iconfont {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translate(0, -50%);
	}

	.address-window .box {
		padding: 45rpx 35rpx;
		width: 690rpx;
		height: 500rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 30rpx auto 100rpx;
	}

	.address-window .box .txt {
		font-weight: 600;
		font-size: 28rpx;
		line-height: 40rpx;
		color: #252525;
	}

	.address-window .box .sign {
		width: 100%;
		line-height: 208rpx;
		text-align: center;
		border-radius: 20rpx;
		border: 1px solid #DDDDDD;
		font-weight: bold;
		font-size: 60rpx;
		color: #CCCCCC;
		margin-top: 60rpx;
	}
	.signimg{
		width: 100%;
		line-height: 208rpx;
		text-align: center;
		border-radius: 20rpx;
		border: 1px solid #DDDDDD;
		font-weight: bold;
		font-size: 60rpx;
		color: #CCCCCC;
	}
</style>